<template>
  <div class="eventLevel">
    <CommonBtn label-name="客户集团管理" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()') " :buttons="buttons" @onButtonClick="onButtonClick">
      <span slot="conditions" v-for="(item,index) of conditions" :key="index" v-if="item.checked">{{item.label+":"+(item.type=='search'?item.proxy:item.value)}}</span>
    </CommonBtn>
    <CommonList ref="list" v-if="!button || (button.event!='add()' && button.event!='edit()' && button.event!='detail()')" :buttons="buttons"
                :columns="columns" :listUrl="listUrl" @tableSelect="tableSelect" :conditions="conditions" @dbClick="openItem"></CommonList>
    <CommonEdit v-if="button && (button.event=='add()' || button.event=='edit()' || button.event=='detail()')"
                :outBtn="button" :props="add"
                :original-data="row" :add-url="$api.API_INSERT_CUSTOMER_GROUP" :edit-url="$api.API_UPDATE_CUSTOMER_GROUP"
                @editBack="editBack"></CommonEdit>
    <search-pop-up :out-btn="button"
                   :props="columns" @close="close"
                   :out-conditions="conditions"
                   @conditionChange="conditionChange"></search-pop-up>
    <CommonExport :out-btn="button" :props="columns"
                  @close="close" :export-url="$api.API_CUSTOMER_GROUP_EXPORT" :conditions="conditions"></CommonExport>

    <EnsurePopUp :out-btn="button" @close="close" @refresh="conditionChange" :original-data="row"
                 :delete-url="$api.API_SET_CUSTOMER_GROUP"></EnsurePopUp>
  </div>
</template>

<script>
    import CommonList from "../../common/CommonList"
    import CommonBtn from "../../common/CommonBtn";
    import CommonEdit from "../../common/CommonEdit";
    import SearchPopUp from "../../common/SearchPopUp";
    import CommonExport from "../../common/CommonExport";
    import EnsurePopUp from "../../common/EnsurePopUp";
    export default {
        name:'customerGroupSetting',
        data(){
            return{
                buttons:[
                    this.$config.BTNS.ADD,
                    this.$config.BTNS.EDIT,
                    this.$config.BTNS.DELETE,
                    this.$config.BTNS.FORBIDEN,
                    this.$config.BTNS.ENABLE,
                    this.$config.BTNS.DETAIL,
                    this.$config.BTNS.EXPORT,
                    this.$config.BTNS.SEARCH
                ],
                columns:[
                    {
                        prop:'customCode',
                        label:'客户集团编码',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'customNameCN',
                        label:'集团中文名称',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'customNameEN',
                        label:'集团英文名称',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'accountCode',
                        label:'预算Account',
                        search:true,
                        type:'text'
                    },
                    {
                        prop:'accountGroupName',
                        label:'预算Account组'
                    },
                    {
                        prop:'customChannelName',
                        label:'客户渠道'
                    },
                    {
                        prop:'repName',
                        label:'客户负责人'
                    },
                    {
                        prop:'destinationName',
                        label:'Destination'
                    },
                    {
                        prop:'customTypeName',
                        label:'集团分类',
                        search:true,
                        type:'search',
                        columns:[
                            {
                                prop:'customTypeCode',
                                label:'集团类型编码',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'customTypeName',
                                label:'集团类型名称',
                                search:true,
                                type:'text'
                            },
                            {
                                prop:'valid',
                                label:'是否有效',
                                search:true,
                                type:'checkbox'
                            }
                        ],
                        searchUrl:this.$api.API_CUSTOMERCLASSIFY_LIST,
                        searchLabel:'客户集团分类',
                        searchProxy:'customTypeCode',
                        searchValue:'pkid',
                        queryProp:'fkCustomType'
                    },
                    {
                        prop:'segmentName',
                        label:'Segment'
                    },
                    {
                        prop:'sortCode',
                        label:'排序'
                    },
                    {
                        prop:'type3',
                        label:'分类三'
                    },
                    {
                        prop:'type4',
                        label:'Vendor'
                    },
                    {
                        prop:'type5',
                        label:'是否上线'
                    },
                    {
                        prop:'valid',
                        label:'是否有效',
                        search:true,
                        type:'checkbox'
                    },
                    {
                        prop:'memo',
                        label:'客户性质'
                    },
                    {
                        prop:'createUserName',
                        label:'创建者'
                    },
                    {
                        prop:'modifyUserName',
                        label:'最后修改者'
                    },
                    {
                        prop:'createTime',
                        label:'创建时间'
                    },
                    {
                        prop:'modifyTime',
                        label:'最后修改时间'
                    }
                ],
                button:null,
                add:{
                    label:'客户集团设定',
                    addItems:[
                        //新增页面-预算Account组，客户渠道，客户负责人有选择按钮
                        //新增页面-集团分类，Segment，Destination有下拉框
                        {name:'客户集团编码',prop:'customCode',type:'text',disable:true,required:true,placeholder:'系统自动生成'},
                        {name:'集团中文名称',prop:'customNameCN',type:'text',required:true},
                        {name:'集团英文名称',prop:'customNameEN',type:'text'},
                        {name:'预算Account',prop:'accountCode',type:'text'},
                        {name:'预算Account组',prop:'fkAccountGroup',type:'search',
                            columns:[
                                {
                                    prop:'accountGroupCode',
                                    label:'预算Account组编码',
                                    search:true,
                                    type:'text'
                                },
                                {
                                    prop:'accountGroupName',
                                    label:'预算Account组名称',
                                    search:true,
                                    type:'text'
                                },
                                {
                                    prop:'valid',
                                    label:'是否有效',
                                    search:true,
                                    type:'checkbox'
                                },
                            ],
                            searchUrl:this.$api.API_ACCOUNTGROUPLIST,
                            searchLabel:'预算Account',
                            proxy:'accountGroupName',
                            searchProxy:'accountGroupName',
                            searchValue:'pkid'
                        },
                        {name:'客户渠道',prop:'fkCustomChannel',type:'search',
                            columns:[
                                {
                                    prop:'customChannelCode',
                                    label:'客户渠道编码',
                                    search:true,
                                    type:'text'
                                },
                                {
                                    prop:'customChannelName',
                                    label:'客户渠道名称',
                                    search:true,
                                    type:'text'
                                },
                                {
                                    prop:'valid',
                                    label:'是否有效',
                                    search:true,
                                    type:'checkbox',
                                    queryProp:'isValid'
                                },
                            ],
                            searchUrl:this.$api.API_CUSTOMER_CHANNEL_LIST,
                            searchLabel:'客户渠道',
                            proxy:'customChannelName',
                            searchProxy:'customChannelName',
                            searchValue:'pkid'
                        },
                        {name:'客户负责人',prop:'fkRep',type:'search',
                            columns:[
                                {
                                    prop:'repCode',
                                    label:'用户账号',
                                    search:true,
                                    type:'text'
                                },
                                {
                                    prop:'repName',
                                    label:'真实姓名',
                                    search:true,
                                    type:'text'
                                },
                                {
                                    prop:'positionName',
                                    label:'所属管理层级',
                                    search:true,
                                    type:'search',
                                    columns:[
                                        {
                                            prop: 'positionName',
                                            label: '职位名称',
                                            type:'text',
                                            search:true
                                        },{
                                            prop: 'createTime',
                                            label: '创建时间'
                                        },{
                                            prop: 'modifyTime',
                                            label: '最后修改时间'
                                        },{
                                            prop: 'isValid',
                                            label: '是否有效'
                                        },{
                                            prop: 'positionCode',
                                            label: '职位代码',
                                            type:'text',
                                            search:true
                                        }
                                    ],
                                    searchUrl:this.$api.API_MANAGEMENTHIERARCHY_LIST,
                                    searchLabel:'职位信息',
                                    proxy:'positionName',
                                    searchProxy:'positionName',
                                    queryProp:'fkPosition',
                                    searchValue:'pkid'
                                },
                                {
                                    prop:'wWID',
                                    label:'WWID',
                                    search:true,
                                    type:'text'
                                },
                                {
                                    prop:'sapCode',
                                    label:'SAP代码',
                                    search:true,
                                    type:'text'
                                },
                                {
                                    prop:'hQOrRegion',
                                    label:'总部/大区',
                                    search:true,
                                    type:'text'
                                }
                            ],
                            searchUrl:this.$api.API_GETTPINFO_LIST,
                            searchLabel:'人员信息',
                            proxy:'repName',
                            searchProxy:'repName',
                            searchValue:'pkid'},
                        {name:'集团分类',prop:'fkCustomType',type:'select',optionsUrl:this.$api.API_CUSTOMERCLASSIFY_LIST,optionProxy:'customTypeName',optionValue:'pkid'},
                        {name:'Segment',prop:'fkSegment',type:'select',optionsUrl:this.$api.API_SEGMENT_LIST,optionProxy:'segmentName',optionValue:'pkid'},
                        {name:'Destination',prop:'fkDestination',type:'select',optionsUrl:this.$api.API_DESTINATION_LIST,optionProxy:'destinationName',optionValue:'pkid'},
                        {name:'排序',prop:'sortCode',type:'text',disable:true,placeholder: '系统自动生成'},
                        {name:'分类三',prop:'type3',type:'text'},
                        {name:'Vendor',prop:'type4',type:'text'},
                        {name:'是否上线',prop:'type5',type:'text'},
                        {name:'客户性质',prop:'memo',type:'textarea',placeholder:'最多100个中文'},
                    ],
                },
                listUrl: this.$api.API_SELECT_CUSTOMER_GROUP_INFO,
                button:null,
                conditions:[],
                row:{}
            }
        },
        methods:{
            onButtonClick(item) {
                if (item.event == 'edit()' || item.event == 'Delete()' || item.event == 'disable()' || item.event == 'enable()') {
                    if (!this.row || JSON.stringify(this.row) == '{}') {
                        this.$message.error("请选择一行数据")
                        return
                    }
                }
                if (item.event == 'add()') {
                    this.row = {}
                }

                this.button = item
            },
            editBack(item) {
                this.button = item
            },
            tableSelect(row) {
                this.row = row
                this.row.createTime = null
                this.row.modifyTime = null
            },
            conditionChange(conditions) {
                this.row = null
                this.$refs.list.search()
            },
            openItem(item) {
                this.button = this.$config.BTNS.DETAIL
            },
            close(item) {
                this.button = item
            }
        },
        components:{CommonExport, SearchPopUp, CommonList,CommonBtn,CommonEdit,EnsurePopUp},
    }
</script>
